package itsm.isperp.module.controller.kpi;

import java.text.ParseException;

import itsm.isperp.module.entity.kpi.KpiSetting;
import itsm.isperp.module.service.kpi.KpiSettingService;
import itsm.isperp.report.IDataResolver;
import itsm.isperp.report.resolver.DataResolver;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.abel533.echarts.Option;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-8-24
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("kpi/data")
public class KpiDataController {

	@Autowired
	KpiSettingService kpiSettingService;

	@RequestMapping(value = { "getData1" })
	@ResponseBody
	public Option getData1(String chartId, String dtype, String gt,
			String stype, HttpServletRequest req) throws ParseException {

		KpiSetting setting = kpiSettingService.findOne(chartId);

		IDataResolver resolver = null;

		resolver = new DataResolver(setting, dtype, gt, stype, true, req);

		return resolver.resolve();
	}

	@RequestMapping(value = { "getData2" })
	@ResponseBody
	public Option getData2(String chartId, String dtype, String gt,
			String stype, HttpServletRequest req) throws ParseException {

		KpiSetting setting = kpiSettingService.findOne(chartId);

		IDataResolver resolver = null;

		resolver = new DataResolver(setting, "month", gt, stype, true, req);

		return resolver.resolveLine();

	}

}
